import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:full_display/common/qxp_color.dart';
import 'package:full_display/common/qxp_style.dart';
import 'package:full_display/generated/l10n.dart';
import 'package:full_display/unit/screen/screen_utility.dart';

class SwitchWidget extends StatefulWidget {
  Function(bool) tapAction;
  bool value;
  SwitchWidget({required this.tapAction, required this.value});

  @override
  State<SwitchWidget> createState() => _SwitchWidgetState();
}

class _SwitchWidgetState extends State<SwitchWidget> {
  @override
  Widget build(BuildContext context) {
    bool _switchValue = widget.value;
    return Container(
      height: 56.0.H,
      decoration: const BoxDecoration(
        color: ColorPlate.backgroundOpacity5,
        borderRadius: BorderRadius.all(Radius.circular(12.0)),
      ),
      child: Padding(
        padding: EdgeInsets.only(left: 20.0.W, right: 20.0.H),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            Text(S.of(context).On_off,
                style: StandardTextStyle.textWhite16Style),
            CupertinoSwitch(
              value: _switchValue,
              activeColor: ColorPlate.app_blue,
              trackColor: ColorPlate.white,
              //dragStartBehavior: DragStartBehavior.start,
              onChanged: (value) {
                //重新构建页面
                setState(() {
                  widget.tapAction(value);
                  _switchValue = value;
                });
              },
            ),
          ],
        ),
      ),
    );
  }
}
